package ATBMS.modles.DAO;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * Database Handle
 */
public class DBHandle {

    private final static String DBDRIVER = "com.mysql.jdbc.Driver";
    private final static String DBURL = "jdbc:mysql://localhost:3306/atbms";
    private final static String DBUSER = "atbms";
    private final static String DBPASSWORD = "atbms";
    private static Connection conn = null;

    /**
     * Connect to database 
     * @return
     */
    public static Connection GetConnection() {
        if (staticInit() == false) {
            return null;
        }
        return conn;
    }

    private static boolean staticInit() {
        if (conn == null) {
            try {
                Class.forName(DBDRIVER);
                conn = DriverManager.getConnection(
                        DBURL, DBUSER, DBPASSWORD);

            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
        }
        return true;
    }
}
